﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.Skins;
using DevExpress.LookAndFeel;
using DevExpress.UserSkins;
using DevExpress.XtraBars;
using DevExpress.XtraBars.Ribbon;
using DevExpress.XtraBars.Helpers;
using HMS_Hospital_Team2._6.DA;
using HMS_Hospital_Team2._6.BL;
using HMS_Hospital_Team2._6.DO;
using HMS_Hospital_Team2._6.GUI;
using System.Collections;


namespace HMS_Hospital_Team2._6
{
    public partial class frmMain : RibbonForm
    {
        string sTenDN = "";
        string sMatKhau = "";
        public frmMain(string stendangnhap, string smatkhau)
        {
            sTenDN = stendangnhap;
            sMatKhau = smatkhau;
            InitializeComponent();
            InitSkinGallery();
            List<phanquyen> thongtintk = BL.NhanVienBL.Loadthongtindangnhap_BL(sTenDN, sMatKhau);//Lay thong tin cua tk vua dang nhap
            if (thongtintk[2].TrangThai == false)//kiem tra quyen de hien thi giao dien phu hop.
            {//khi nv nhap lieu va nv thu tien dang nhap va he thong.
                barbtnDichVu.Enabled = false;
                barbtnLoaiPhong.Enabled = false;
                barbtnNhanVien.Enabled = false;
                barbtnNhomDV.Enabled = false;
                barbtnPhongBan.Enabled = false;
            }
        }

        void InitSkinGallery()
        {
            SkinHelper.InitSkinGallery(rgbiSkins, true);
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            // show info status bar
            siStatus.Caption = DateTime.Now.ToLongDateString();
            siInfo.Caption = "Tên đăng nhập: "+sTenDN;
        }

        private void btnLoaiPhong_ItemClick(object sender, ItemClickEventArgs e)
        {
            //Panel chinh
            pnMain.Controls.Clear();
            UcLoaiPhongBan UcLoaiPB = new UcLoaiPhongBan();
            UcLoaiPB.Dock = System.Windows.Forms.DockStyle.Fill;
            pnMain.Controls.Add(UcLoaiPB);
        }

        private void btnPhongBan_ItemClick(object sender, ItemClickEventArgs e)
        {
            pnMain.Controls.Clear();
            UcPhongBan UcPhongban = new UcPhongBan();
            UcPhongban.Dock = System.Windows.Forms.DockStyle.Fill;
            pnMain.Controls.Add(UcPhongban);
        }

        private void btnNhomDV_ItemClick(object sender, ItemClickEventArgs e)
        {
            pnMain.Controls.Clear();
            UcNhomDichVu UcNhomDV = new UcNhomDichVu();
            UcNhomDV.Dock = System.Windows.Forms.DockStyle.Fill;
            pnMain.Controls.Add(UcNhomDV);
        }

        private void btnDichVu_ItemClick(object sender, ItemClickEventArgs e)
        {
            pnMain.Controls.Clear();
            UcDichVu UcDichvu = new UcDichVu();
            UcDichvu.Dock = System.Windows.Forms.DockStyle.Fill;
            pnMain.Controls.Add(UcDichvu);
        }

        private void btnNhanVien_ItemClick(object sender, ItemClickEventArgs e)
        {
            pnMain.Controls.Clear();
            UcNhanVien UcNhanvien = new UcNhanVien();
            UcNhanvien.Dock = System.Windows.Forms.DockStyle.Fill;
            pnMain.Controls.Add(UcNhanvien);
        }

        private void iAbout_ItemClick(object sender, ItemClickEventArgs e)
        {
            Form frmabout = new frmAbout();
            frmabout.ShowDialog();
        }

        private void barbtnThongkedoanhthu_Main_ItemClick(object sender, ItemClickEventArgs e)
        {
            pnMain.Controls.Clear();
            UcThongkedoanhthu UcThongkedoanhthu = new UcThongkedoanhthu();
            UcThongkedoanhthu.Dock = System.Windows.Forms.DockStyle.Fill;
            pnMain.Controls.Add(UcThongkedoanhthu);
        }

        private void barbtnThutien_Main_ItemClick(object sender, ItemClickEventArgs e)
        {
            frmSelectPostion frmchonvitri = new frmSelectPostion(sTenDN, sMatKhau);
            frmchonvitri.ShowDialog();
            string sMaPB = frmchonvitri.sMaPB;
            string sMaBan = frmchonvitri.sMaban;
            int sVaiTro = frmchonvitri.sVaitro;
            bool blcheck = frmchonvitri.blclick;
            List<phanquyen> thongtintk = BL.NhanVienBL.Loadthongtindangnhap_BL(sTenDN, sMatKhau);
            if (sVaiTro == 0 && blcheck == true)//Load man hinh cua nhan vien nhap lieu
            {
                pnMain.Controls.Clear();
                UcLapHoaDonThuTien Uclaphdthutien = new UcLapHoaDonThuTien(sTenDN, sMatKhau, sMaPB, sMaBan);
                Uclaphdthutien.Dock = System.Windows.Forms.DockStyle.Fill;
                pnMain.Controls.Add(Uclaphdthutien);
                //barbtnThutien_Main.Enabled = false;
            }
            else//Load man hinh cua nhan vien thu tien
            {
                if (sVaiTro == 1 && blcheck == true)//Load man hinh cua nhan vien thu tien
                {
                    pnMain.Controls.Clear();
                    UcXacNhanThuTien Ucxacnhanthutien = new UcXacNhanThuTien(sTenDN, sMatKhau, sMaPB, sMaBan);
                    Ucxacnhanthutien.Dock = System.Windows.Forms.DockStyle.Fill;
                    pnMain.Controls.Add(Ucxacnhanthutien);
                    //barbtnThutien_Main.Enabled = false;
                }
            }
        }

        private void barDanhsachbienlai_Main_ItemClick(object sender, ItemClickEventArgs e)
        {
            pnMain.Controls.Clear();
            UcBaoCaoHoadon UcBaoCaoBienLai = new UcBaoCaoHoadon();
            UcBaoCaoBienLai.Dock = System.Windows.Forms.DockStyle.Fill;
            pnMain.Controls.Add(UcBaoCaoBienLai);
        }

        private void barDanhsachthutien_Main_ItemClick(object sender, ItemClickEventArgs e)
        {
            pnMain.Controls.Clear();
            UcBaocaodanhsachthutien UcBaocaoDSthutien = new UcBaocaodanhsachthutien();
            UcBaocaoDSthutien.Dock = System.Windows.Forms.DockStyle.Fill;
            pnMain.Controls.Add(UcBaocaoDSthutien);
        }

        private void barButtonItem4_ItemClick(object sender, ItemClickEventArgs e)
        {
            frmChangePassword frmDoiMatKhau = new frmChangePassword(sTenDN, sMatKhau);
            frmDoiMatKhau.ShowDialog();
            this.Hide();
            frmLogin frmlog = new frmLogin();
            frmlog.ShowDialog();
        }

        private void btnLogOut_ItemClick(object sender, ItemClickEventArgs e)
        {
            this.Hide();
            frmLogin frm = new frmLogin();
            frm.ShowDialog();
        }

        private void barLogout_ItemClick(object sender, ItemClickEventArgs e)
        {
            this.Hide();
            Form frm = new frmLogin();
            frm.ShowDialog();
        }

        private void frmMain_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (test != true)
            {
                DialogResult result;
                result = MessageBox.Show("Bạn có chắc chắn thoát không?", "Thông báo!", MessageBoxButtons.YesNo,
                    MessageBoxIcon.Warning);
                if (result == DialogResult.Yes)
                {
                    Application.ExitThread();
                }
                if (result == DialogResult.No)
                {
                    e.Cancel = true;
                }
            }
            test = false;
        }
        bool test = false;
    }
}